
/* 
    对mysql操作进行封装
*/
var mysql = require("mysql")

function sqlQuery(sql, callback) {
    var connection = mysql.createConnection({
        //开发环境
        host: 'localhost',
        user: 'root',
        password: '123456',
        database: 'xhy_blog'

        /*  //正式环境
         host: '118.178.182.26',
         user: 'xhy_data',
         password: 'FpWXx5PSJZ26BsEh',
         database: 'xhy_data' */

    })
    connection.connect()
    connection.query(sql, (err, data) => {
        if (err) throw err
        callback(data);
    })
    closeMysql(connection)
}
function closeMysql(connection) {
    connection.end((err) => {
        if (err) { console.log("数据库关闭失败" + err); }
        else { console.log("断开连接成功"); }
    })
}

module.exports = { sqlQuery }